﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFWS.XHandler.Core;
using JKF.Substructure;
using JKF.Entities.Model;
using JKF.BusinessLayer.BLL;
using System.Data;
using JKF.Entities;

namespace JKF.HandlerLayer.SMS
{
    public class Sms_Charge_LogHandler : AHttpHandler
    {
        public override void ProcessRequest()
        {
            //所有错误和异常将抛出异常.正常执行程序则在方法则返回数据
            try
            {
                this.Manager(Utils.GetActionName);
            }
            catch (Exception ex)
            {
                //将错误抛到客户端(以Json格式)
                Utils.ToClient(true, ex.Message);
                //写日志
                AppLogger.Log(ex.Message, ex);
            }
        }

        public void GetChargeLogByShop()
        {      
            bllSMS_CHARGE_LOG chargeLog = new bllSMS_CHARGE_LOG();
            var shopCode = P("shopCode");
            Response.Write(JsonSerializer.Serialize(chargeLog.GetChargeLogByShop(shopCode), Utils.GetDateFormat));
        }

        /// <summary>
        /// 短信充值，添加充值日志
        /// </summary>
        public void SaveChargeLog()
        {
            try
            {
                bllSMS_CHARGE_LOG bllChargeLog = new bllSMS_CHARGE_LOG();
                var shopCode = P("SHOP_CODE");
                var CHARGE_COUNT =Int32.Parse(P("CHARGE_COUNT"));
                var MEMO = P("MEMO");
                bllChargeLog.SaveChargeLog(shopCode, CHARGE_COUNT, MEMO);
                Response.Write(JsonSerializer.Serialize(new ResponseInf { MessageCode = "Ok", Message = "操作成功", Data = shopCode }));
            }
            catch (Exception exp)
            {
                Response.Write(JsonSerializer.Serialize(new ResponseInf { MessageCode = "Error", Message = exp.Message.FilterJs() }));
            }
        }
    }
}
